<div id="tab-wrapper">
	<h3>Shopping Cart side links</h3>
	<hr>
	<div id="sidelinksdiv">
		<div id="sidelinksactivediv">&nbsp;</div>
		<div id="sidelinksinactivediv">&nbsp;</div>
		<div style="clear:both">&nbsp;</div>
		<button id='linkssavebtn'>Save Links</button>
		<hr>
	</div>
</div>

<script type="text/javascript">

function getActiveLinks(){
	   $.getJSON('<?php print base_url(); ?>guicontroller/getactivelinks', function(data) {
		   
	 		 var htmltext='<div class="droppable3 ui-widget-header" id="element 0">';
	 		htmltext=htmltext+'<p>Active</p>';
	 		htmltext=htmltext+'<ul id="ul-screen-active" key="0" class="sortable boxy">';

	 		$.each(data['links'], function(key, val) {
				htmltext=htmltext+"<li link="+val+">"+key+"</li>";
	 		});
	 		htmltext=htmltext+'</ul></div>';

	 		$('#sidelinksactivediv').html(htmltext);

	 		getInactievLinks();

		});
}

function getInactievLinks(){
	   $.getJSON('<?php print base_url(); ?>guicontroller/getinactivelinks', function(data) {
		   
	 		 var htmltext='<div class="droppable3 ui-widget-header" id="element 0">';
	 		htmltext=htmltext+'<p>InActive Links</p>';
	 		htmltext=htmltext+'<ul id="ul-screen-inactive" key="0" class="sortable boxy">';

	 		$.each(data['links'], function(key, val) {
				htmltext=htmltext+"<li link="+val+">"+key+"</li>";
	 		});
	 		htmltext=htmltext+'</ul></div>';

	 		htmltext=$('#sidelinksactivediv').html()+htmltext;
	 		$('#sidelinksactivediv').html(htmltext);


		
				 list = document.getElementById("ul-screen-inactive");
				 DragDrop.makeListContainer( list );

				 list = document.getElementById("ul-screen-active");
				 DragDrop.makeListContainer( list );
	 		
	   });
}

$(document).ready(function(){

	getActiveLinks();

	   $('#linkssavebtn').button().click(function(){


			var activelinksarray=new Array();

			var i=0;
			//Active links
			$('#ul-screen-active').children().each(function(){
					console.log($(this));
					activelinksarray[i]=$(this).attr('link');
					
					i++;
			});

			//post 
			var activedata='&activedata='+JSON.stringify(activelinksarray);

			$.ajax({
				type: "POST",
					url: "<?php print base_url(); ?>guicontroller/saveactivelinks",
					data: activedata,
					success : function(data){
						console.log(data);
					}
			});

			
		
			var inactivelinksarray=new Array();
			
			i=0;
			//Inactive links
			$('#ul-screen-inactive').children().each(function(){
				console.log($(this).attr('link'));
				inactivelinksarray[i]=$(this).attr('link');
				i++;
			});

			//post 
			var inactivedata='&inactivedata='+JSON.stringify(inactivelinksarray);

			$.ajax({
				type: "POST",
				url: "<?php print base_url(); ?>guicontroller/saveinactivelinks",
					data: inactivedata,
					success : function(data){
						console.log(data);
					}
			});
			
		
	   });
	   
	   
	

});
</script>
